﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Styx.Plugins;
using Styx.Common;
using Styx.WoWInternals;
using System.Windows.Media;

namespace GB2ConfigLoader
{
    public class GB2ConfigLoader : HBPlugin
    {
        public override string Author { get { return "NiV"; } }
        public override Version Version { get { return new Version(0, 0, 42); } }
        public override string Name { get { return "GB2ConfigLoader"; } }
        public override bool WantButton { get { return true; } }
        public override string ButtonText { get { return "force config load"; } }

        public GB2ConfigLoader()
        {
            Logging.Write(Styx.Common.LogLevel.Verbose, Colors.Crimson, string.Format("[GB2ConfigLoader]: attaching"));
            Styx.CommonBot.BotEvents.OnBotStarted += evStart;
            Styx.CommonBot.BotEvents.OnBotStopped += evStop;
        }

        private void evStart(object evObject)
        {
            if (Styx.CommonBot.BotManager.Current.Name == "Gatherbuddy2")
            {
                LoadConfig();
            }
        }

        private void LoadConfig(){

                Logging.Write(Styx.Common.LogLevel.Verbose, Colors.Crimson, string.Format("[GB2ConfigLoader]: loading config..."));
                XElement gb2config = Styx.CommonBot.Profiles.ProfileManager.CurrentProfile.XmlElement.Element(XName.Get("GatherbuddySettings"));
                Bots.Gatherbuddy.GatherbuddySettings.Instance.LoadFromXML(gb2config);

        }

        public void evStop(object evObject)
        {
            Logging.Write(Styx.Common.LogLevel.Verbose, Colors.Crimson, string.Format("[GB2ConfigLoader]: detaching"));
        }

        public override void Pulse()
        {

        }

        public override void Dispose()
        {

        }

        public override void OnButtonPress()
        {
            LoadConfig();
        }

    }
}
